#include<bits/stdc++.h>
using namespace std;
#define file(x)freopen(x  ".in","r",stdin);freopen(x  ".out","w",stdout);
char buff[1<<22],*p1=buff,*p2=buff+(1<<22)-1;
template<typename T>void qread(T&x){
   // cin>>x;return;
    int f=0;x=0;char c=getchar();
    while(!isdigit(c)){if(c=='-')f^=1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}//i had to not use cim
template<typename T>void qreadf(T&x){
   int z;qread(z);x=z;
}//i had to not use cim
int _,n,m,l,x;long double d[1000005],p[1000005],v[1000005],a[1000005];
pair<long double,int>lastt;
struct seg{long double l,r,kql,kqr;};vector<seg>segx;
int sol(){
    sort(segx.begin(),segx.end(),[](seg x,seg y){return x.r<y.r;});
    int cnt=0,idx=0,ans=0;
    while(idx<segx.size()){
    //    cout<<idx<<' '<<segx[idx].l<<' '<<segx[idx].r<<endl;
        while(cnt<=m&&
        (segx[idx].kqr?p[cnt]<=segx[idx].r:p[cnt]<segx[idx].r)
        )cnt++;
        cnt--;ans++;while(idx<segx.size()&&
        (segx[idx].kql?segx[idx].l<=p[cnt]:segx[idx].l<p[cnt]))idx++;
    }return ans;
}
int  main(){
    file("detect");
    cin>>_;while(_--){
        qread(n);qread(m);qread(l);qread(x);
        for(int i=1;i<=n;i++){qreadf(d[i]);qreadf(v[i]);qreadf(a[i]);}
        for(int i=1;i<=m;i++)qreadf(p[i]);
        int cnt=0;sort(p+1,p+m+1);
        for(int i=1;i<=n;i++)
        if(a[i]==0){if((d[i]<=p[m])&&(v[i]>x))cnt++,lastt=max(lastt,{d[i],0});}
        else if(a[i]>=0){
            long double t=(x-v[i])/a[i];t=max(t,0.l);
            long double s=v[i]*t+.5*a[i]*t*t+d[i];
            if(s<p[m]||(s==p[m]&&v[i]>x))cnt++,lastt=max(lastt,{s,v[i]<=x});
        }else{
            long double t=(v[i]-x)/-a[i];if(t<=0)continue;
            long double s=v[i]*t+.5*a[i]*t*t+d[i];
            if(lower_bound(p+1,p+m+1,d[i])!=lower_bound(p+1,p+m+1,s))
            cnt++,segx.push_back({d[i],s,1,0});
        }
        cout<<cnt<<' '<<flush;
        if(cnt)segx.push_back({lastt.first,l,!lastt.second,1});
        if(cnt==99987){//for(auto i:segx)cout<<i.l<<' '<<i.r<<' '<<i.kql<<' '<<i.kqr<<endl;
        }
        cout<<m-sol()<<endl;segx.clear();
        lastt=make_pair(0.l,0);
    }
}